package com.cqu.lpss.controller;

import com.cqu.lpss.pojo.Result;
import com.cqu.lpss.utils.JwtUtils;
import io.jsonwebtoken.Claims;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@RestController
public class CheckTokenController {
    @RequestMapping("/check_token")
    public Result check_token(HttpServletRequest request){
        String authorizationHeader = request.getHeader("Authorization");
        String jwt = authorizationHeader.substring("\"Bearer ".length());
        jwt = jwt.replaceAll("^\"|\"$", "");
        Claims claims = JwtUtils.parseJWT(jwt);
        return Result.success(claims);


    }
}
